home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1999 #1
/
Amiga Plus 1999 #1.iso
/
System-Boost
/
Workbench
/
WinTool
/
WinTool.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-06-28
|
10KB
|
376 lines
// WinTool.c by Fredrik Söderberg
// Any questions, suggestions, anything, email me.
// ///S and ///E means fold, S for Start and E for End (GoldEd)
///S includes
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <intuition/IntuitionBase.h>
#include <libraries/gadtools.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <stdio.h>
#include <string.h>
///E
///S Defines for gadgets
#define TITLEG 1
#define WIDTHG 2
#define HEIGHTG 3
#define LEFTEDGEG 4
#define TOPEDGEG 5
#define MOUSEXG 6
#define MOUSEYG 7
#define CLOSEG 8
#define FORCEG 9
#define ZIPG 10
#define EXECUTEG 11
#define SAFEG 12
///E
///S Global
struct IntuitionBase *IntuitionBase;
struct Library *GadToolsBase;
struct Window *wtwin;
struct TextAttr topaz8 = {"topaz.font", 8, 0, 0};
struct Gadget *titleg, *widthg, *heightg, *topg, *leftg, *mxg, *myg, *closeg;
struct Gadget *forceg, *zipg, *executeg, *safeg;
struct Gadget *gadgetlist=NULL;
///E
///S prototypes
void killwin(struct Window *);
void executewin(struct Window *, int );
unsigned int getwinstat(struct Window *);
void eventloop(void);
struct Window *createwin(struct Screen *,struct VisualInfo *);
int main(void);
///E
///S main(void)
int main(void)
{
struct Screen *wtscreen;
struct VisualInfo *wtvi;
if(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37L))
{
if(GadToolsBase = OpenLibrary("gadtools.library", 37L))
{
if(wtscreen = LockPubScreen(NULL))
{
if(wtvi = GetVisualInfo(wtscreen, TAG_END))
{
if(wtwin = createwin(wtscreen, wtvi))
{
GT_RefreshWindow(wtwin, NULL);
eventloop();
CloseWindow(wtwin);
if(gadgetlist) FreeGadgets(gadgetlist);
}
else puts("Could not open buttons");
FreeVisualInfo(wtvi);
}
else puts("Could not open VisualInfo");
UnlockPubScreen(NULL, wtscreen);
}
else puts("Could not LockPubScreen");
CloseLibrary(GadToolsBase);
}
else puts("Could not open gadtools.library V37");
}
else puts("Could not open intuition.library V37");
return 0;
}
///E
///S executewin(win, title, tlen)
void executewin(struct Window *win, int tlen)
{
LONG le=0, te=0, w=0, h=0;
LONG czip=FALSE, cclear=FALSE, cforce=FALSE, csafe=FALSE;
char *title;
GT_GetGadgetAttrs(titleg, wtwin,NULL,
GTST_String, &title, TAG_END);
if(strlen(title)!=tlen)
title[tlen]='\0';
strcpy(win->Title, title);
GT_GetGadgetAttrs(leftg, wtwin,NULL,
GTIN_Number, &le, TAG_END);
GT_GetGadgetAttrs(topg, wtwin,NULL,
GTIN_Number, &te, TAG_END);
GT_GetGadgetAttrs(widthg, wtwin,NULL,
GTIN_Number, &w, TAG_END);
GT_GetGadgetAttrs(heightg, wtwin,NULL,
GTIN_Number, &h, TAG_END);
GT_GetGadgetAttrs(zipg, wtwin,NULL,
GTCB_Checked, &czip, TAG_END);
GT_GetGadgetAttrs(closeg, wtwin,NULL,
GTCB_Checked, &cclear, TAG_END);
GT_GetGadgetAttrs(forceg, wtwin,NULL,
GTCB_Checked, &cforce, TAG_END);
GT_GetGadgetAttrs(safeg, wtwin,NULL,
GTCB_Checked, &csafe, TAG_END);
SetWindowTitles(win, win->Title, (UBYTE *) ~0);
if(csafe)
{
win->MinWidth=1;
win->MinHeight=1;
}
ChangeWindowBox(win, le, te, w, h);
if(czip)
ZipWindow(win);
if(cclear)
killwin(win);
if(cforce)
CloseWindow(win);
getwinstat(win);
}
///E
///S getwinstat(win)
unsigned int getwinstat(struct Window *win)
{
GT_SetGadgetAttrs(titleg, wtwin,NULL,
GTST_String, win->Title, TAG_END);
GT_SetGadgetAttrs(widthg, wtwin,NULL,
GTIN_Number, win->Width, TAG_END);
GT_SetGadgetAttrs(heightg, wtwin,NULL,
GTIN_Number, win->Height, TAG_END);
GT_SetGadgetAttrs(topg, wtwin,NULL,
GTIN_Number, win->TopEdge, TAG_END);
GT_SetGadgetAttrs(leftg, wtwin,NULL,
GTIN_Number, win->LeftEdge, TAG_END);
GT_SetGadgetAttrs(mxg, wtwin,NULL,
GTIN_Number, win->MouseX, TAG_END);
GT_SetGadgetAttrs(myg, wtwin,NULL,
GTIN_Number, win->MouseY, TAG_END);
return(strlen(win->Title));
}
///E
///S eventloop(void)
void eventloop(void)
{
struct IntuiMessage *intmess;
struct Gadget *gad;
int going = TRUE, tlen=0;
ULONG class, code;
struct Window *win;
win = wtwin;
while(going)
{
WaitPort(wtwin->UserPort);
while((intmess = GT_GetIMsg(wtwin->UserPort)) && going)
{
class = intmess->Class;
code = intmess->Code;
gad = (struct Gadget *) intmess->IAddress;
GT_ReplyIMsg(intmess);
switch(class)
{
case IDCMP_GADGETUP:
if(gad->GadgetID == EXECUTEG)
{
executewin(win, tlen);
tlen = getwinstat(win);
}
break;
case IDCMP_INACTIVEWINDOW:
{
win = IntuitionBase->ActiveWindow;
tlen = getwinstat(win);
}
break;
case IDCMP_CLOSEWINDOW:
going = FALSE;
break;
case VANILLAKEY:
if(code==27)
going = FALSE;
break;
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(wtwin);
GT_EndRefresh(wtwin, TRUE);
break;
}
}
}
}
///E
///S win = createwin(screen, vi, gadgetlist)
struct Window *createwin(struct Screen *screen, struct VisualInfo *vi)
{
struct NewGadget newgadget;
struct Window *win;
titleg = CreateContext(&gadgetlist);
newgadget.ng_TextAttr = &topaz8;
newgadget.ng_VisualInfo = vi;
newgadget.ng_LeftEdge = 84;
newgadget.ng_TopEdge = 15;
newgadget.ng_Width = 250;
newgadget.ng_Height = 12;
newgadget.ng_GadgetText = "Title";
newgadget.ng_GadgetID = TITLEG;
newgadget.ng_Flags = 0;
titleg = CreateGadget(STRING_KIND, titleg, &newgadget,
GTST_MaxChars, 255, TAG_END);
newgadget.ng_TopEdge += 15;
newgadget.ng_Width = 40;
newgadget.ng_GadgetText = "Width";
newgadget.ng_GadgetID = WIDTHG;
widthg = CreateGadget(INTEGER_KIND, titleg, &newgadget,
TAG_END);
newgadget.ng_TopEdge += 15;
newgadget.ng_GadgetText = "Height";
newgadget.ng_GadgetID = HEIGHTG;
heightg = CreateGadget(INTEGER_KIND, widthg, &newgadget,
TAG_END);
newgadget.ng_TopEdge += 15;
newgadget.ng_GadgetText = "LeftEdge";
newgadget.ng_GadgetID = LEFTEDGEG;
leftg = CreateGadget(INTEGER_KIND, heightg, &newgadget,
TAG_END);
newgadget.ng_TopEdge += 15;
newgadget.ng_GadgetText = "TopEdge";
newgadget.ng_GadgetID = TOPEDGEG;
topg = CreateGadget(INTEGER_KIND, leftg, &newgadget,
TAG_END);
newgadget.ng_TopEdge += 15;
newgadget.ng_GadgetText = "MouseX";
newgadget.ng_GadgetID = MOUSEXG;
mxg = CreateGadget(INTEGER_KIND, topg, &newgadget,
TAG_END);
newgadget.ng_LeftEdge += 120;
newgadget.ng_GadgetText = "MouseY";
newgadget.ng_GadgetID = MOUSEYG;
myg = CreateGadget(INTEGER_KIND, mxg, &newgadget,
TAG_END);
newgadget.ng_LeftEdge = 245;
newgadget.ng_TopEdge = 42;
newgadget.ng_GadgetText = "Close Window";
newgadget.ng_GadgetID = CLOSEG;
closeg = CreateGadget(CHECKBOX_KIND, myg, &newgadget, TAG_END);
newgadget.ng_LeftEdge += 35;
newgadget.ng_Flags = PLACETEXT_ABOVE;
newgadget.ng_GadgetText = "With Force";
newgadget.ng_GadgetID = FORCEG;
forceg = CreateGadget(CHECKBOX_KIND, closeg, &newgadget, TAG_END);
newgadget.ng_LeftEdge = 245;
newgadget.ng_TopEdge += 15;
newgadget.ng_Flags = PLACETEXT_LEFT;
newgadget.ng_GadgetText = "Zip Window";
newgadget.ng_GadgetID = ZIPG;
zipg = CreateGadget(CHECKBOX_KIND, forceg, &newgadget, TAG_END);
newgadget.ng_LeftEdge = 280;
newgadget.ng_TopEdge += 15;
newgadget.ng_Flags = PLACETEXT_LEFT;
newgadget.ng_GadgetText = "Remove size limits";
newgadget.ng_GadgetID = SAFEG;
safeg = CreateGadget(CHECKBOX_KIND, zipg, &newgadget, TAG_END);
newgadget.ng_LeftEdge = 260;
newgadget.ng_TopEdge = 90;
newgadget.ng_Width = 100;
newgadget.ng_Flags = PLACETEXT_IN;
newgadget.ng_GadgetText = "Execute";
newgadget.ng_GadgetID = EXECUTEG;
executeg = CreateGadget(BUTTON_KIND, safeg, &newgadget, TAG_END);
if(executeg)
{
if(!(win = OpenWindowTags(NULL,
WA_Gadgets, gadgetlist,
WA_Width, 380,
WA_Height, 110,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_Activate, TRUE ,
WA_IDCMP, IDCMP_REFRESHWINDOW |
IDCMP_CLOSEWINDOW |
CHECKBOXIDCMP |
INACTIVEWINDOW |
VANILLAKEY,
WA_PubScreen, screen,
WA_Title, "WinTool",
WA_ScreenTitle, "WinTool 1.11 by Fredrik Söderberg. (virus free:)",
TAG_END)))
{
puts("Could not open window");
FreeGadgets(gadgetlist);
gadgetlist=FALSE;
return(FALSE);
}
}
else
return(FALSE);
return(win);
}
///E
///S killwin(win)
// Sends a IDCMP_CLOSEWINDOW to the window win
void killwin(struct Window *win)
{
struct IntuiMessage msg;
struct MsgPort *port;
if(!(port = CreateMsgPort()))
{
Permit();
return;
}
msg.ExecMessage.mn_Node.ln_Succ = NULL;
msg.ExecMessage.mn_Node.ln_Pred = NULL;
msg.ExecMessage.mn_Node.ln_Type = NT_MESSAGE;
msg.ExecMessage.mn_Node.ln_Name = NULL;
msg.ExecMessage.mn_Node.ln_Pri = 0;
msg.ExecMessage.mn_ReplyPort = port;
msg.ExecMessage.mn_Length = sizeof(struct IntuiMessage);
msg.Class = IDCMP_CLOSEWINDOW;
msg.Code = 0;
msg.Qualifier = 0;
msg.IAddress = NULL;
msg.MouseX = 0;
msg.MouseY = 0;
msg.Seconds = 0;
msg.Micros = 0;
msg.IDCMPWindow = win;
msg.SpecialLink = NULL;
PutMsg(win->UserPort, (struct Message *)&msg);
WaitPort(port);
DeleteMsgPort(port);
}
///E